while 1:
    j = input()
    if 1000 <= int(j) <= 9999:
        break
    else:
        print(0)
def isPrime(f):
    if f == 1: return False
    test = True
    h = f - 1
    while h > 1:
        if not f % h:
            test = False
            break
        h -= 1
    return test

y = []
for i in range(len(j)):
    for h in range(i + 1, len(j) + 1):
        f = int(j[i:h])
        if isPrime(f):
            y += [f]
print(max(y) if y else 0)
